package org.huangrui.design.pattern.observer;

public class TestObservers {
    public static void main(String[] args) {
        ParentHealth p = new ParentHealth();
        Weather w = new Weather();

        Children s = new Children();
        CommunityCareWorker c = new CommunityCareWorker();
        Doctor d = new Doctor();

        //订阅健康主题消息
        p.registerObserver(s);
        p.registerObserver(c);
        p.registerObserver(d);

        //订阅天气主题消息
        w.registerObserver(s);
        w.registerObserver(c);

        System.out.println("健康主题变化演示：");
        p.setMessage("发烧");
        System.out.println("===================");
        p.setMessage("摔跤");

        System.out.println("====================");
        p.removeObserver(d);//取消订阅

        p.setMessage("感冒");

        System.out.println("====================");
        System.out.println("天气主题变化演示：");
        w.setMessage("下雪");
    }
}
